package paint;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;

public class ProgressBar extends PaintComponent {
	protected int x;
	protected int y;
	private int percentage;
	private boolean striped;
	private Color outColor;
	protected Color fillColor;
	private Color textColor;
	protected String text;

	public ProgressBar(int x, int y, int percentage, boolean striped, Color outlineColor, Color fillColor,
			Color textColor, String text) {
		super(new Rectangle(x, y, 0, 0));
		this.x = x;
		this.y = y;
		this.percentage = percentage;
		this.striped = striped;
		outColor = outlineColor;
		this.fillColor = fillColor;
		this.textColor = textColor;
		this.text = text;
	}

	@Override
	public void paint(Graphics g) {
		FontMetrics fm = g.getFontMetrics();
		Rectangle textBounds = fm.getStringBounds(text, g).getBounds();

		bounds.width = textBounds.width;
		bounds.height = textBounds.height;

		if (striped) {
			Paint paint = ((Graphics2D) g).getPaint();
			((Graphics2D) g).setPaint(new GradientPaint(0, 0, new Color(0, 0, 0, 75), 1, 1, new Color(0, 0, 0, 200),
					true));
			g.fillRect(getX() - 2, getY() - textBounds.height + 1, (int) ((textBounds.width + 5) * (percentage * .01)),
					textBounds.height + 5);

			((Graphics2D) g).setPaint(paint);
		} else {
			g.setColor(new Color(0, 0, 0, 160));
			g.fillRect(getX() - 2, getY() - textBounds.height + 1, textBounds.width + 5, textBounds.height + 5);

			g.setColor(fillColor);
			g.fillRect(2 + getX() - 2, getY() - textBounds.height + 3,
					(int) ((textBounds.width + 5) * (percentage * .01)) - 2, textBounds.height + 2);
		}

		g.setColor(outColor);
		g.drawRect(getX() - 2, getY() - textBounds.height + 1, textBounds.width + 5, textBounds.height + 5);

		for (int i = 1; i > -1; i--) {
			g.setColor(textColor);
			if (i == 1) {
				g.setColor(Color.BLACK);
			}

			g.drawString(text, getX() + 1, getY() + 1);
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
